<?php


namespace App\Transformers\Store;


use App\Models\LiveAnchor;
use App\Models\StorePink;
use App\Transformers\Order\OrderTransformer;
use App\Transformers\Store\StoreCombinationTransformer;
use App\Transformers\User\UserTransformer;
use League\Fractal\TransformerAbstract;

class StorePinkTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['storeCombination','order','user'];

    public function transform(StorePink $data)
    {
        return [
            'id' => $data->id,
            'user_id' => $data->user_id ?? "",
            'product_id' => $data->product_id ?? "",
            'order_id' => $data->order_id ?? "",
            'order_id_key' => $data->order_id_key ?? "",
            'combination_goods_id' => $data->combination_goods_id ?? "",
            'head_id' => $data->head_id ?? "",
            'people' => $data->people ?? "",
            'total_num' => $data->total_num ?? "",
            'total_price' => $data->total_price ?? "",
            'price' => $data->price ?? "",
            'start_time' => $data->start_time ?? "",
            'stop_time' => $data->stop_time ?? "",
            'is_tpl' => $data->is_tpl ?? 0,
            'is_refund' => $data->is_refund ?? 0,
            'status' => $data->statusEnum[$data->status] ?? "",
            'is_virtual' => $data->is_virtual ?? 0,
            'user' => $data->user ?? 0,
            'storeCombination' => $data->storeCombination ?? "",
            'store_pink_count' => $data->store_pink_count + 1 ?? '',
            'created_at' => $data->created_at->format("Y-m-d H:i:s") ? $data->created_at->format("Y-m-d H:i:s") : '',
            'updated_at' => $data->created_at->format("Y-m-d H:i:s") ? $data->updated_at->format("Y-m-d H:i:s") : '',
        ];
    }

    /**
     *额外包含拼团商品数据
     */

    public function includeStoreCombination(StorePink $storePink)
    {
        return $this->item($storePink->storeCombination, new StoreCombinationTransformer());
    }

    /**
     * 额外包含订单数据
     */
    public function includeOrder(StorePink $storePink)
    {
        return $this->item($storePink->order, new OrderTransformer());
    }

    /**
     *额外包含用户数据
     */

    public function includeUser(StorePink $storePink)
    {
        return $this->item($storePink->user, new UserTransformer());
    }
}
